import TcpSocket from './TcpSocket';
import Coordtransform from '../../utils/Coordtransform';

const Toc = new TcpSocket(think.config('videoConfig'));

// const nameSpace = think.config('nameSpace');
class CatalogVideo extends think.Service {
  constructor() {
    super();
    Toc.on('catalogs', async(data) => {
      const list = data.list;
      for (const value of list) {
        const lat = value.Lat;
        const lng = value.Lng;
        const type = value.type;
        if (Number(type) !== 2 && lat !== 0) {
          // 离线将wgs84地球坐标做换成百度坐标
          const points = Coordtransform.wgs84tobd09(lng, lat);
          value.Lng = points[0];
          value.Lat = points[1];
        }
        this.db['basic_catalog_video'].upsert(value);
      }
    });
    Toc.on('error', (data) => {
      think.logger.error(data);
    });
  }

  ptzControl(deviceId, cmdType, speed) {
    Toc.ptz(deviceId, cmdType, speed);
  }
}

export default CatalogVideo;
